<?php

$filename = isset($_GET['filename']) ? $_GET['filename'] : '';
$uploadDir = './upload/';
$filePath = $uploadDir . basename($filename); 

if (file_exists($filePath) && is_file($filePath)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename=' . urlencode($filename));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($filePath));
    
    ob_clean();
    flush();
    readfile($filePath);
    exit;
} else {
    echo "<script>alert('文件不存在！');window.history.back();</script>";
}
?>